/**
 * @template {{ ret: number; msg: string; }} C
 * @template {{ [key: string]: C; }} T
 * @param {T} dict
 * @returns {{[K in keyof T]: C;} & {$map: { [key: string]: string; }}}
 * **/
function check (dict) {
    const newDict = {
        $map: {}
    }

    for (const k in dict) {
        const code = dict[k]

        if (newDict.$map[code.ret]) {
            throw new Error(`'Duplicate \`ret\` value \`${code.ret}\`'`)
        }

        newDict.$map[code.ret] = code.msg
        newDict[k] = code
    }

    return newDict
}

module.exports = check({
    OK: { ret: 0, msg: 'ok' },
    UNKNOWN: { ret: 1, msg: 'Unknown error' },
})
